import jieba
import jieba.posseg as pseg
import re
f1=open("D://test.txt","r",encoding='utf-8').read()
fonts=jieba.lcut(f1)
counts={}
for font in fonts:
    if len(font)==1:
        continue
    else:
        counts[font]=counts.get(font,0)+1
items=list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
print("次数排名")
for i in range(5):
    open("output.txt","a",encoding="utf-8").write(str(items[i]))
    print(items[i])
f1.close()